package com.cy.api;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Entity{
    String value() default "";
}

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD,ElementType.METHOD})
@interface ID{
    String value() default "";
}



@Entity("t_user")
class User{
    @ID("uid")
    private Integer id;
}


public class AnnotationTests {
    public static void main(String[] args) throws NoSuchFieldException {
//        User user = new User();
//        Entity annotation = user.getClass().getAnnotation(Entity.class);
//        String value = annotation.value();
//        System.out.println(value);
//
//        Field id = user.getClass().getDeclaredField("id");
//        ID ids = id.getAnnotation(ID.class);
//        System.out.println(ids.value());


        Class<?> targetCls=User.class;
        Entity entity = targetCls.getAnnotation(Entity.class);
        String entityValue = entity.value();
        System.out.println(entityValue);

        Field f = targetCls.getDeclaredField("id");
        ID id = f.getAnnotation(ID.class);
        String idValue = id.value();
        System.out.println(idValue);


    }
}
